package com.spider.util;


import com.spider.task.PrintTimeTask;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class PrintTimeScheduler {

    public static void main(String[] args) throws Exception{
        String cron = "0/3 * * * * ? 2020-2021";

        //1、创建一个调度器
        SchedulerFactory sf = new StdSchedulerFactory();
        Scheduler s = sf.getScheduler();

        //2、创建任务调度
        JobDetail jd = JobBuilder.newJob(PrintTimeTask.class)
                .withIdentity("job1","group1").build();

        //3、创建触发器
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("tr1","triGroup1")
                .withSchedule(CronScheduleBuilder.cronSchedule(cron)).build();

        //4、把触发器与任务调度结合
        s.scheduleJob(jd,trigger);
        s.start();

    }
}
